package com.spt.springbootzhsx.dao;

import com.spt.springbootzhsx.entity.back.OrderBack;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.Date;

@Mapper
public interface OrderDao {
    @Select("select oid,movies.order.pid,plan.mid,movies.order.uid,plan.cid,username,mname,cname,ostate,buyTime,playTime,movies.order.price,orow,ocolumn,pic " +
            "from movie,movies.order,user,plan,cinema " +
            "where movie.mid=plan.mid and user.uid=movies.order.uid and plan.pid=movies.order.pid and cinema.cid=plan.cid and movies.order.uid=#{uid}")
    ArrayList<OrderBack> getOrderHistory(Integer uid);


    @Select("select oid,movies.order.pid,plan.mid,movies.order.uid,plan.cid,username,mname,cname,ostate,buyTime,playTime,movies.order.price,orow,ocolumn,pic " +
            "from movie,movies.order,user,plan,cinema "+
            "where movie.mid=plan.mid and user.uid=movies.order.uid and plan.pid=movies.order.pid and cinema.cid=plan.cid")
    ArrayList<OrderBack> getAllOrder();

    @Select("select oid,movies.order.pid,plan.mid,movies.order.uid,plan.cid,username,mname,cname,ostate,buyTime,playTime,movies.order.price,orow,ocolumn,pic " +
            "from movie,movies.order,user,plan,cinema " +
            "where movie.mid=plan.mid and user.uid=movies.order.uid and plan.pid=movies.order.pid and cinema.cid=plan.cid and username=#{username}")
    ArrayList<OrderBack> getOrderByUsername(String username);


    @Select("select oid,movies.order.pid,plan.mid,movies.order.uid,plan.cid,username,mname,cname,ostate,buyTime,playTime,movies.order.price,orow,ocolumn,pic " +
            "from movie,movies.order,user,plan,cinema " +
            "where movie.mid=plan.mid and user.uid=movies.order.uid and plan.pid=movies.order.pid and cinema.cid=plan.cid and mname=#{mname}")
    ArrayList<OrderBack> getOrderByMname(String mname);

    @Select("select count(oid) from movies.order where buyTime>curdate()-1")
    Integer getOrderCount_LastOne();

    @Select("select count(oid) from movies.order where buyTime>curdate()-2")
    Integer getOrderCount_LastTwo();

    @Select("select count(oid) from movies.order where buyTime>curdate()-3")
    Integer getOrderCount_LastThree();

    @Select("select count(oid) from movies.order where buyTime>curdate()-4")
    Integer getOrderCount_LastFour();

    @Select("select count(oid) from movies.order where buyTime>curdate()-5")
    Integer getOrderCount_LastFive();

    @Select("select count(oid) from movies.order where buyTime>curdate()-6")
    Integer getOrderCount_LastSix();

    @Select("select count(oid) from movies.order where buyTime>curdate()-7")
    Integer getOrderCount_LastSeven();

    @Select("select count(oid) " +
            "from movies.order,movie,plan " +
            "where movies.order.pid=plan.pid and plan.mid=movie.mid and movies.order.uid=#{uid} and mtype like concat('%',#{mtype},'%')")
    Integer getOrderCountByUidAndMtype(@Param("uid") Integer uid, @Param("mtype") String mtype);
}

